/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package trace;

/**
 *
 * @author Julien Cassis
 */
public class staticPredictor implements Runnable {
        public static int TAKEN = 1;
        public static int NOTTAKEN = 0;
        private int misprediction = 0;
        private int count = 0;
        private Reader traceFile;
        private Writer outputFile;
        private int option = 0;

        public staticPredictor(Reader iFile,Writer oFile,int option){
            this.traceFile = iFile;
            this.outputFile = oFile;
            this.option = option;
        }

        public void run(){
             String traceStr;
            String[] fileOption = new String[2];
            traceStr = traceFile.readLine();
            System.out.println("Starting static " + traceFile.filename + " " + option);
            int outcome;
            while(traceStr != null){
                fileOption = Reader.parseString(traceStr);
                outcome = Integer.parseInt(fileOption[1]);
                if(outcome !=this.option){
                    this.misprediction += 1;
                }
                this.count ++;
                traceStr = traceFile.readLine();
            }
         System.out.println("Done running static " + traceFile.filename + " " + this.option);
         this.summary();
         outputFile.close();
        }

        public void summary(){
           this.outputFile.writeToFile("misprediciton,count");
           this.outputFile.writeToFile(this.misprediction + "," + this.count);
        }
}
